package com.xscr.forum.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.xscr.forum.mapper.ForumImageMapper;
import com.xscr.forum.po.ForumCircle;
import com.xscr.forum.po.ForumImage;
import com.xscr.forum.service.ForumImageService;
import com.xscr.mybatis.utility.PageBean;

public class ForumImageServiceImpl implements ForumImageService {

	@Autowired
	private ForumImageMapper forumImageMapper;
	
	@Override
	public int saveForumImage(ForumImage forumImage) throws Exception {
		return forumImageMapper.insertSelective(forumImage);
	}

	@Override
	public int saveListForumImage(List<ForumImage> forumImage) throws Exception {
		return forumImageMapper.insertListForumImage(forumImage);
	}

	@Override
	public int deleteForumImageById(Integer id) throws Exception {
		ForumImage forumImage = new ForumImage();
		forumImage.setImageId(id);
		forumImage.setStatus(-1);
		
		return forumImageMapper.updateByPrimaryKeySelective(forumImage);
	}

	@Override
	public int updateForumImage(ForumImage forumImage) throws Exception {
		return forumImageMapper.updateByPrimaryKeySelective(forumImage);
	}

	@Override
	public ForumImage findForumImageById(Integer id) throws Exception {
		return forumImageMapper.selectByPrimaryKey(id);
	}

	@Override
	public PageBean<ForumImage> findForumImageByConditions(
			PageBean<ForumImage> pageBean) throws Exception {
		
		List<ForumImage> selectForumImageListPage = forumImageMapper.selectForumImageListPage(pageBean);
		
		pageBean.setResult(selectForumImageListPage);
		
		return pageBean;
	}

	@Override
	public List<ForumImage> findForumImageByConditions(ForumImage forumImage)
			throws Exception {
		PageBean<ForumImage> pageBean = new PageBean<ForumImage>();
		
		pageBean.setParameter(forumImage);
			
		return forumImageMapper.selectForumImageListPage(pageBean);
	}
	
	@Override
	public List<ForumImage> findForumImageByTopicId(Integer topicId)
			throws Exception {
		ForumImage forumImage=new ForumImage();
		
		forumImage.setTopicId(topicId);
		
		PageBean<ForumImage> pageBean = new PageBean<ForumImage>();
		
		pageBean.setParameter(forumImage);
			
		return forumImageMapper.selectForumImageListPage(pageBean);
	}

}
